package com.socket;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class FileServer {
    public static void main(String[] args) throws IOException {
        ServerSocket server = new ServerSocket(9090);
        Socket socket = server.accept();

        try (InputStream is = socket.getInputStream();
             FileOutputStream fos = new FileOutputStream("D:\\FileIo\\received_file.txt")) {

            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = is.read(buffer)) != -1) {
                fos.write(buffer, 0, bytesRead);
            }
            System.out.println("File received!");
        }
    }
}
